from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.charts import Bar, Timeline
from pyecharts.components import Table
from pyecharts.options import ComponentTitleOpts


def timeline_table(data,range,rangetype,title,legend,color):
    headers = ["City name", "Area", "Population", "Annual Rainfall"]
    tl = Timeline().add_schema(play_interval=3000, height=40, is_rewind_play=False, is_loop_play=True,
                               is_auto_play=True)
    rows1 = [
        ["Brisbane", 5905, 1857594, 1146.4],
        ["Adelaide", 1295, 1158259, 600.5],
        ["Darwin", 112, 120900, 1714.7],
        ["Hobart", 1357, 205556, 619.5],
        ["Sydney", 2058, 4336374, 1214.8],
        ["Melbourne", 1566, 3806092, 646.9],
        ["Perth", 5386, 1554769, 869.4],
    ]
    for day in sorted(list(set(range))):
        rows = data[data[rangetype] == day].values # 选取指定日期地区数据

        table = Table()
        table.add(headers, rows1)
        table.set_global_opts(
            title_opts=ComponentTitleOpts(title="Table-基本示例", subtitle="我是副标题支持换行哦")
        )
        tl.add(table, "{}".format(day))
    return tl
